#include<func.h>
#define N 20000000
typedef struct
{
    long num;
    pthread_mutex_t mutex;
}data_t;
void*sigfunc(void * p)
{
    data_t * d=(data_t*)p;
    for(int i=0;i<N;i++)
    {
        pthread_mutex_lock(&d->mutex);
        d->num++;
        pthread_mutex_unlock(&d->mutex);
    }
}
int main()
{
    data_t d;
    d.num=0;
    int ret=pthread_mutex_init(&d.mutex,NULL);
    THREAD_ERR_CHECK(ret,"pthread_mutex_init");
    pthread_t pthid;
     ret=pthread_create(&pthid,NULL,sigfunc,(void*)&d);
    THREAD_ERR_CHECK(ret,"pthread_create")
    int i;
    for(i=0;i<N;i++)
    {
        pthread_mutex_lock(&d.mutex);
        d.num++;
        pthread_mutex_unlock(&d.mutex);
    }
    ret=pthread_join(pthid,NULL);
    THREAD_ERR_CHECK(ret,"pthread_join")
    printf("result=%ld\n",d.num);
    ret=pthread_mutex_destroy(&d.mutex);
    THREAD_ERR_CHECK(ret,"pthread_mutex_destroy");
    return 0;

}